<template>
  <div>

    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户</el-breadcrumb-item>
      <el-breadcrumb-item>组织架构</el-breadcrumb-item>
    </el-breadcrumb>

    <el-form :inline="true" :model="formInline" class="query-form" label-width="4rem">
      <el-form-item label=" ">
        <el-input placeholder="输入关键字进行过滤" v-model="filterText">
      </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">过滤</el-button>
      </el-form-item>
    </el-form>

    <div class="box">
      <!-- <el-input placeholder="输入关键字进行过滤" v-model="filterText">
      </el-input> -->

      <el-tree class="tree" :data="data4" node-key="id" default-expand-all :expand-on-click-node="false" :render-content="renderContent">
      </el-tree>
    </div>

  </div>
</template>

<style>
.query-form {
  margin-top: 20px;
  padding-top: 25px;
  background-color: #f2f2f2;
}

.box {
  padding: 20px;
  margin-top: 20px;
  border: 1px solid #ebebeb;
  border-radius: 3px;
  transition: 0.2s;
}

/* .tree,
.tree-filter {
  margin-top: 20px;
} */

.table,
.pagination {
  margin-top: 30px;
}

.pagination {
  text-align: right;
  padding-right: 2rem;
}
</style>

<script>
let id = 1000;

export default {
  name: "Systems",
  data() {
    const data = [
      {
        id: 1,
        label: "技术部",
        children: [
          {
            id: 3,
            label: "研发组",
          },
           {
            id: 4,
            label: "运维组",
          }
        ]
      },
      {
        id: 2,
        label: "综合管理部",
      }
    ];
    return {
      data4: JSON.parse(JSON.stringify(data))
    };
  },
  methods: {
    append(data) {
      const newChild = { id: id++, label: "testtest", children: [] };
      if (!data.children) {
        this.$set(data, "children", []);
      }
      data.children.push(newChild);
    },
    remove(node, data) {
      const parent = node.parent;
      const children = parent.data.children || parent.data;
      const index = children.findIndex(d => d.id === data.id);
      children.splice(index, 1);
    },

    renderContent(h, { node, data, store }) {
      return (
        <span class="custom-tree-node">
          <span>{node.label}</span>
          &nbsp;&nbsp;&nbsp;&nbsp;
          <span>
            <el-button
              // size="mini"
              type="text"
              on-click={() => this.append(data)}
            >
              <i class="el-icon-edit-outline" />
            </el-button>
            <el-button
              // size="mini"
              type="text"
              on-click={() => this.append(data)}
            >
              <i class="el-icon-circle-plus" />
            </el-button>
            <el-button
              // size="mini"
              type="text"
              on-click={() => this.remove(node, data)}
            >
              <i class="el-icon-remove" />
            </el-button>
          </span>
        </span>
      );
    }
  }
};
</script>
